load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor", "render_config")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_test")

crates_vendor(
    name = "crates_vendor",
    annotations = {
        "axum": [crate.annotation(
            compile_data_glob = ["**/*.md"],
        )],
    },
    mode = "remote",
    packages = {
        "axum": crate.spec(
            version = "0.4.0",
        ),
        "hyper": crate.spec(
            features = ["full"],
            version = "0.14.22",
        ),
        "mime": crate.spec(
            version = "0.3",
        ),
        "serde_json": crate.spec(
            version = "1.0",
        ),
        # TODO: This dependency is added and pinned forward due to the
        # following issue: https://github.com/hyperium/hyper/issues/3038
        "socket2": crate.spec(
            features = ["all"],
            version = "0.4.7",
        ),
        "tokio": crate.spec(
            features = ["full"],
            version = "1.26.0",
        ),
        "tower": crate.spec(
            features = ["util"],
            version = "0.4",
        ),
        "tower-http": crate.spec(
            features = ["trace"],
            version = "0.2.1",
        ),
        "tracing": crate.spec(
            version = "0.1",
        ),
        "tracing-subscriber": crate.spec(
            version = "0.3",
        ),
    },
    # Demonstrate that `crates_vendor` can accept a render_config. To regen this target, simply
    # navigate to this directory and run `bazel run //vendor_remote_pkgs:crates_vendor`.
    render_config = render_config(
        regen_command = "See https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/vendor_local_pkgs/BUILD.bazel",
    ),
    repository_name = "crates_vendor_pkgs",
)

rust_binary(
    name = "vendor_remote",
    srcs = glob(["**/*.rs"]),
    edition = "2018",
    deps = [
        "@crates_vendor_pkgs//:axum",
        "@crates_vendor_pkgs//:hyper",
        "@crates_vendor_pkgs//:mime",
        "@crates_vendor_pkgs//:serde_json",
        "@crates_vendor_pkgs//:tokio",
        "@crates_vendor_pkgs//:tower",
        "@crates_vendor_pkgs//:tower-http",
        "@crates_vendor_pkgs//:tracing",
        "@crates_vendor_pkgs//:tracing-subscriber",
    ],
)

rust_test(
    name = "unit_test",
    crate = ":vendor_remote",
    edition = "2018",
)
